///
/// Override the ${Export Button}_Click and customize the
/// export button functionality
/// Also if the export button is Image button then, second parameter type is ImageClickEventArgs.
/// If the button is of "Button" type then modify the parameter type to EventArgs.
///
public override void ${Export Button}_Click(object sender, ImageClickEventArgs args)
{
try
{
DbUtils.StartTransaction();
WhereClause whereStr = this.CreateWhereClause();
//Create the order by object
BaseClasses.Data.OrderBy ob = null;
int pageIndex = 0;
int pageSize = 1000;
// Get the instance of Data Access class
${${Table}RecordClassName}[] recList = ${${Table}ClassName}.GetRecords(whereStr, ob, pageIndex, pageSize);
string exportedData = "";
exportedData = this.ExportFunction(recList);
// Export the data.
this.Page.AttachFile("MyFile.csv", exportedData);
}
catch (Exception ex)
{
// Report error message to the user
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "UNIQUE_SCRIPTKEY", ex.Message);
}
finally
{
DbUtils.EndTransaction();
}
}
///
/// This method limits the number of columns that get exported.
///
public string ExportFunction( ${${Table}RecordClassName}[] recList)
{
// Add column names to the export data.
string exportLine = ${${Table}ClassName}.${Primary Key}.InternalName + ",";
exportLine += ${${Table}ClassName}.${Export Field}.InternalName + ",";
// Finally, add the line break after adding the last column heading.
string exportedData = (exportLine + "\r\n");
// Get column values from each record in table.
foreach (${${Table}RecordClassName} rec in recList)
{
exportLine = "";
exportLine += rec.${Primary Key} + ",";
exportLine += rec.${Export Field} + ",";
// Add the line break after each record.
exportedData += exportLine + "\r\n";
}
return exportedData;
}
|